﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionePolveriLib.Facades;
using BrightIdeasSoftware;
using GestionePolveriLib.BL;

namespace GestionePolveri2
{
    public partial class NewPolvereElenco : Form
    {
        private List<PolvereExt> m_polveriSelezionate = null;

        public List<PolvereExt> PolveriSelezionate
        {
            get { return m_polveriSelezionate; }
            set { m_polveriSelezionate = value; }
        }

        public NewPolvereElenco()
        {
            InitializeComponent();

            if (!DesignMode)
            {
                LoadPolveri();

                m_polveriSelezionate = new List<PolvereExt>();
            }
        }

        private void LoadPolveri()
        {
            PolvereFacade fcf = new PolvereFacade();
            fcf.RunAsync(() => fcf.GetAllEssential(), (result) =>
            {
                this.objectListViewPolveri.AddDecoration(new EditingCellBorderDecoration { UseLightbox = true });
                this.objectListViewPolveri.SetObjects((List<PolvereExt>)result);
            });
        }

        private void txtCerca_TextChanged(object sender, EventArgs e)
        {
            TextMatchFilter filter = null;
            if (!String.IsNullOrEmpty(txtCerca.Text))
            {
                filter = TextMatchFilter.Prefix(this.objectListViewPolveri, txtCerca.Text);
                objectListViewPolveri.AdditionalFilter = filter;
            }
            else
            {
                objectListViewPolveri.AdditionalFilter = null;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            foreach (PolvereExt polvere in objectListViewPolveri.CheckedObjects)
            {
                m_polveriSelezionate.Add(polvere);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
